#include "bullet2.h"

Bullet2::Bullet2()
{
    //加载子弹资源
    m_Bullet.load(BULLET2_PATH);

    //子弹坐标初始化
    m_X = 0;
    m_Y = 0;

    //子弹移动速度
    m_Speed = BULLET2_SPEED;

    //子弹闲置
    m_Free = true;

    //子弹的矩形边框
    m_Rect.setWidth(m_Bullet.width());
    m_Rect.setHeight(m_Bullet.height());
    m_Rect.moveTo(m_X, m_Y);
}

/* 设置子弹坐标 */
void Bullet2::setPosition(int x, int y)
{
    m_X = x - m_Bullet.width()/2;
    m_Y = y - m_Bullet.height()/2;
    m_Rect.moveTo(m_X, m_Y);
}

/* 更新子弹坐标 */
void Bullet2::updatePosition()
{
    //如果子弹闲置不更新
    if(m_Free)
    {
        return;
    }
    //子弹Y坐标加
    m_Y += m_Speed;
    m_Rect.moveTo(m_X, m_Y);

    //如果子弹射出屏幕更新为闲置
    if(m_Y > GAME_HEIGHT)
    {
        m_Free = true;
    }
}

